package com.jungle.client;

import com.jungle.bfi.domain.vo.DataCategoryVo;
import com.jungle.client.control.BasicDialog;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;

import java.io.IOException;
import java.net.URL;
import java.util.function.Consumer;

import static com.jungle.client.FxApplication.bundle;

public class DataCategoryEditController extends BasicDialog<DataCategoryVo> {
    @FXML
    private TextField nameField;
    @FXML
    private TextField codeField;
    private String id;
    @Override
    public void loadData(DataCategoryVo data) {
        this.id = data.getId();
        this.nameField.setText(data.getName());
        this.codeField.setText(data.getCode());
    }

    @Override
    public DataCategoryVo storeData() {
        DataCategoryVo data = new DataCategoryVo();
        data.setId(id);
        data.setName(nameField.getText());
        data.setCode(codeField.getText());
        return data;
    }
    private static final URL FXML_URL = DataCategoryEditController.class.getResource("dataCategory-edit.fxml");
    private static final String TITLE = bundle.getString("dataCategory.dialog.title");

    public static void showAddDialog(DataCategoryVo dataSetVo, Consumer<DataCategoryVo> consumer) throws IOException {

        String title = bundle.getString("dialog.title.prefix.add") + TITLE;

        new DataCategoryEditController().showDialog(FXML_URL, title, dataSetVo, consumer);
    }

    public static void showEditDialog(DataCategoryVo dataSetVo, Consumer<DataCategoryVo> consumer) throws IOException {

        String title = bundle.getString("dialog.title.prefix.edit") + TITLE;

        new DataCategoryEditController().showDialog(FXML_URL, title, dataSetVo, consumer);
    }
}
